using System;
using System.Windows;
using System.Collections.Generic;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using NobleTech.Products.CreatureKingdom.Utils;
using NobleTech.Products.CreatureKingdom;

namespace NobleTech.Products.CreatureKingdom
{
    /// <summary>
    /// Draw a T in the target Organism
    /// </summary>
    public class CrazyRenderer : IRenderer
    {
        public CrazyRenderer(OrganismStats stats)
        {
        }

        ImageBrush ImageBrush;

        // The rendered brush must face downward and have a Viewport of (0,0,1,1). The client will do the size scaling, rotation and translation and will change the opacity upon death.        
        public Brush Render(OrganismInfo info, PointD Location, double DirectionFacing)
        {
            // At this time, the brush is independent of the arguments, so there is no need to compute it every time.
            if (ImageBrush == null)
            {
                byte[] PixelData = new byte[32 * 32 * 3];
                WorldStats.RandomGenerator.NextBytes(PixelData);
                BitmapSource Bitmap = BitmapSource.Create(32, 32, 96, 96, PixelFormats.Rgb24, BitmapPalettes.WebPaletteTransparent, PixelData, 32 * 3);
                ImageBrush = new ImageBrush(Bitmap);
                ImageBrush.Viewport = new Rect(0, 0, 1, 1);
            }
            return ImageBrush;
        }
    }
}
       